<?php

namespace common\services;

use common\models\Parameters;
use common\models\card\CardBrand;
/**
*  参数获取服务
*/
class ParamsService
{
	
	/**
	 * 获取当前 key 的值
	 */
	public static function getParams($key){
		// todo : 将当前的 kEY 放入文件缓存
		$params = Parameters::find()
					->select(["item","value"])
					->where(["field"=> CardBrand::CARD_BRAND_TYPE,"isValid" => 1])
					->orderBy("iorder asc")->all();
		$data = [];
		if ($params) {
			foreach ($params as $item) {
				$key = pow(2,$item->value);
				$data[$key] = $item->item;
			}
		}

		return $data;
	}

	/**
	 * 根据当前的 Key 获取排序
	 */
	public static function getParamsByKey($key){
		$params = Parameters::find()
					->select(["item","value"])
					->where(["field"=> trim($key),"isValid" => 1])
					->orderBy("iorder asc")->all();
		$data = [];
		if ($params) {
			foreach ($params as $item) {
				$data[$item->value] = $item->item;
			}
		}

		return $data;
	}

	
}